package test.bingo;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.jasper.tagplugins.jstl.core.ForEach;

import test.common.MySqlMap;


import com.ibatis.sqlmap.client.SqlMapClient;

public class BingoDAO {

	public void insertNum(BingoPan pan) throws SQLException {
		System.out.println("insertNum start!");
		SqlMapClient sqlMap = MySqlMap.getSqlMapInstance();	
		int d = sqlMap.update("bingo.updateNum",pan);
		System.out.println("update : " + d);
		
	}
	
	public void createPan() throws SQLException {
		int[] j = new int[25];
		BingoPan pan;
		System.out.println("createPan DAO start!");
			for (int i = 0;i < 25 ;i++ )
			{
				j[i] = i+1;
			}
			
		for (int z = 0; z < 200; z++) {
			
			
			for (int i = 0; i < 25 ;i++ ){	
				
				int temp = 0;
				int r = ((int)(Math.random()*24)+1);
				temp = j[i];				
				j[i] = j[r];
				j[r] =  temp;
									
			}
		}	
			for (int i = 0; i < j.length; i++) {
				pan = new BingoPan(i,j[i],null);
				System.out.println("빙고 판 "+ i + " 번째 " +j[i]);
				SqlMapClient sqlMap = MySqlMap.getSqlMapInstance();	
				sqlMap.insert("bingo.insertNum",pan);
			}
			
		
	}
	
	public ArrayList<BingoPan> getPan() throws SQLException {
		ArrayList<BingoPan> pan;
		SqlMapClient sqlMap = MySqlMap.getSqlMapInstance();	
		pan = (ArrayList<BingoPan>)sqlMap.queryForList("bingo.getPan");
		System.out.println(pan);
		return pan;
	}
	
	public void delete() throws SQLException {
		SqlMapClient sqlMap = MySqlMap.getSqlMapInstance();	
		sqlMap.delete("bingo.delete");		
	}
	public ArrayList<Ranking> getScore() throws SQLException{
		ArrayList<Ranking> ranking=null;
		SqlMapClient sqlMap = MySqlMap.getSqlMapInstance();	
		ranking = (ArrayList<Ranking>)sqlMap.queryForList("bingo.getRanking");
		return ranking;		
	}
	
	

	
}
